package com.lvyq.myplayer.presenter.impl

import com.lvyq.myplayer.base.BaseListPresenter.Companion.TYPE_INIT
import com.lvyq.myplayer.base.BaseListPresenter.Companion.TYPE_LOAD_MORE
import com.lvyq.myplayer.base.BaseView
import com.lvyq.myplayer.model.HomeItemBean
import com.lvyq.myplayer.model.HomeItemBeans
import com.lvyq.myplayer.net.ResponseHandler
import com.lvyq.myplayer.net.home.HomeRequest
import com.lvyq.myplayer.presenter.inter.HomePresenter

/**
 * 文件描述：HomePresenterImpl
 * 作者：lvyq
 * 创建时间：2025-02-21
 * 修改时间：2025-02-21
 */
class HomePresenterImpl(var homeView: BaseView<HomeItemBean>):HomePresenter, ResponseHandler<HomeItemBean> {


    /**
     * 加载更多
     */
    override fun loadMore(pageNum: Int) {
       HomeRequest(TYPE_LOAD_MORE,pageNum,this).excute()

    }

    /**
     * 初始加载
     */
    override fun loadDatas() {
      HomeRequest(TYPE_INIT,1,this).excute()
    }

    override fun destoryView() {
        if (homeView!=null){
            homeView==null
        }
    }


    //失败
    override fun onError(type:Int,msg: String) {
        homeView.onError(msg)
    }

    //成功
    override fun onSuccess(type:Int,result: HomeItemBean) {
        //区分初始化数据 和加载数据

       /// var list = result.rows as ArrayList<HomeItemBeans>
        when(type){
            TYPE_INIT->homeView.loadSuccess(result,result.total)
            TYPE_LOAD_MORE->homeView.loadMore(result,result.total)
        }

    }
}